// ButtonSamples.cs
//

namespace ContribSample.jQueryUI
{
    using Script.Contrib.jQueryUI;
    using System;
    using jQueryApi;
    using System.Collections;

    public static class ButtonSamples
    {
        /// <summary>
        /// Default Functionality
        /// </summary>
        public static void Button()
        {
            jQueryUI.Select("button, input:submit, a").Button();

            jQuery.Select("a").Click(delegate(jQueryEvent e)
            {
                e.PreventDefault();
            });
        }

        /// <summary>
        /// Radios sample
        /// </summary>
        public static void Radios()
        {
            jQueryUI.Select("#radio").Buttonset();
        }

        /// <summary>
        /// Checkboxes sample
        /// </summary>
        public static void Checkboxes()
        {
            jQueryUI.Select("#check").Button();
            jQueryUI.Select("#format").Buttonset();
        }

        /// <summary>
        /// Checkboxes sample
        /// </summary>
        public static void Icons()
        {
            jQueryUI.Select("button:first").Button(new Dictionary("icons", new Dictionary("primary", "ui-icon-locked"), "text", false))
                .Next().Button(new Dictionary("icons", new Dictionary("primary", "ui-icon-locked")))
                .Next().Button(new Dictionary("icons", new Dictionary("primary", "ui-icon-gear", "secondary", "ui-icon-triangle-1-s")))
                .Next().Button(new Dictionary("icons", new Dictionary("primary", "ui-icon-gear", "secondary", "ui-icon-triangle-1-s"), "text", false));
        }

        /// <summary>
        /// Toolbar sample
        /// </summary>
        public static void Toolbar()
        {
            jQueryUI.Select("#beginning").Button(new Dictionary("icons", new Dictionary("primary", "ui-icon-seek-start"), "text", false));
            jQueryUI.Select("#rewind").Button(new Dictionary("icons", new Dictionary("primary", "ui-icon-seek-prev"), "text", false));
            jQueryUI.Select("#play").Button(new Dictionary("icons", new Dictionary("primary", "ui-icon-play"), "text", false)).Click(delegate(jQueryEvent e){
                Dictionary options = new Dictionary();
                if (jQuery.This.GetText() == "play")
                {
                    options["label"] = "pause";
                    options["icons"] = new Dictionary("primary", "ui-icon-pause");
                }
                else
                {
                    options["label"] = "play";
                    options["icons"] = new Dictionary("primary", "ui-icon-play");
                }
                jQueryUI.Select(jQuery.This).Button("option", options);
            });
            jQueryUI.Select("#stop").Button(new Dictionary("icons", new Dictionary("primary", "ui-icon-stop"), "text", false)).Click(delegate(jQueryEvent e)
                {
                    jQueryUI.Select("#play").Button("option", new Dictionary("icons", new Dictionary("primary", "ui-icon-play"), "text", false));
                });
            jQueryUI.Select("#forward").Button(new Dictionary("icons", new Dictionary("primary", "ui-icon-seek-next"), "text", false));
            jQueryUI.Select("#end").Button(new Dictionary("icons", new Dictionary("primary", "ui-icon-seek-end"), "text", false));
            jQueryUI.Select("#shuffle").Button();
            jQueryUI.Select("#repeat").Buttonset();
        }

        /// <summary>
        /// SplitButton sample
        /// </summary>
        public static void SplitButton()
        {
            jQueryUI.Select("#rerun")
                .Button()
                .Click(delegate(jQueryEvent e) {
                    Script.Alert("Running the last action");
                })
                .Next().Cast<jQueryUIObject>()
                .Button(new Dictionary("icons", new Dictionary("primary", "ui-icon-triangle-1-s"), "text", false))
                .Click(delegate(jQueryEvent e){
                    Script.Alert("Could display a menu to select an action");
                })
                .Cast<jQueryUIObject>().Parent().Buttonset();
        }
    }
}
